package com.archtecture.control.utils;

import javax.naming.InitialContext;
import javax.naming.NamingException;

//"ejb:SPGF_EAR/SPGF_EJB//PersistenceFacade!com.archtecture.control.facedes.PersistenceFacadeRemote?stateless"
public final class ServiceLocatorJBoss {

	private final static String	NOME_EAR;
	private final static String	NOME_EJB;
	private final static String	PACOTE_FACADES;
	private final static String	TIPO_EJB;

	static {
		NOME_EAR = "SPGF_EAR";
		NOME_EJB = "SPGF_EJB";
		PACOTE_FACADES = "com.archtecture.control.facedes";
		TIPO_EJB = "stateless";
	}

	public static Object realizarLookup(String simpleNameImpl) {

		StringBuilder contexto = new StringBuilder();
		contexto.append("ejb:");
		contexto.append(NOME_EAR);
		contexto.append("/");
		contexto.append(NOME_EJB);
		contexto.append("//");
		contexto.append(simpleNameImpl);
		contexto.append("!");
		contexto.append(PACOTE_FACADES);
		contexto.append(".");
		contexto.append(simpleNameImpl + "Remote");
		contexto.append("?");
		contexto.append(TIPO_EJB);

		try {
			return new InitialContext().lookup(contexto.toString());
		} catch (NamingException nex) {
			// TODO implementar log
		}

		return null;
	}
}
